/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package br.com.aluguel.niceshot;

import br.com.niceshot.Conexao;
import br.com.niceshot.PresetQueries;
import java.util.LinkedHashMap;

/**
 *
 * @author Alexandre
 */
public class AluguelQueries extends PresetQueries {

    public String insertAluguel(LinkedHashMap<String, String> dataAluguel) {
        try {
            con = Conexao.getConnection();
            stat = con.createStatement();

            Object[] arrayNmCampo = dataAluguel.keySet().toArray();
            Object[] arrayValores = dataAluguel.values().toArray();
            String query = "INSERT INTO aluguel (";

            for (int i = 0; i < dataAluguel.size(); i++) {
                if (i > 0) {
                    query += ",";
                }
                query += " " + String.valueOf(arrayNmCampo[i]);
            }

            query += ") VALUES (";

            for (int i = 0; i < dataAluguel.size(); i++) {
                if (i > 0) {
                    query += ", ";
                }
                query += " " + String.valueOf(arrayValores[i]);
            }
            query += ")";

            stat.executeUpdate(query);
            
            return selectMaxTableId("aluguel", "id_aluguel");

        } catch (Exception e) {
            return ("Error");

        } finally {

            try {
                rs.close();
            } catch (Exception e) {
            }
            try {
                con.close();
            } catch (Exception e) {
            }
            try {
                stat.close();
            } catch (Exception e) {
            }
        }
        //dataAluguel.put("Success", "True");
    }

    
}
